//
//  UILabel+Extention.swift
//  MicroBlog
//
//  Created by 002 on 15/10/16.
//  Copyright © 2015年 002. All rights reserved.
//

import UIKit

extension UILabel {
    
    /// 便利构造函数
    ///
    /// :param: title    title
    /// :param: fontSize fontSize，字体大小默认14
    /// :param: color    color，字体颜色默认深灰色
    ///
    /// :returns: UILabel
    convenience init(title: String,
        fontSize : CGFloat = 14,
        color : UIColor = UIColor.darkGrayColor()) {
        self.init()
            
        text = title
        // 避免使用纯黑色
        textColor = color
        font = UIFont.systemFontOfSize(fontSize)
        numberOfLines = 0
        textAlignment = NSTextAlignment.Center
    
        sizeToFit()
    }
    
    /// 便利构造函数
    ///
    /// :param: title    title
    /// :param: fontSize fontSize，字体大小默认14
    /// :param: color    color，字体颜色默认深灰色
    /// :param: screenInsert 相对与屏幕左右的缩紧，默认为0，局中显示，如果设置，则左对齐
    /// :returns: UILabel
    convenience init(title: String,
        fontSize : CGFloat = 14,
        color : UIColor = UIColor.darkGrayColor(),
        screenInsert : CGFloat) {
            self.init()
            
            text = title
            // 避免使用纯黑色
            textColor = color
            font = UIFont.systemFontOfSize(fontSize)
            numberOfLines = 0
            textAlignment = NSTextAlignment.Center
            
            numberOfLines = 0
            if screenInsert == 0 {
                textAlignment = .Center
            } else {
                // 设置换行高度
                preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 2 * screenInsert
                textAlignment = .Left
                
            }
            sizeToFit()
    }
}